﻿//普通alert弹窗
function AlertBox(msg, title, time) {
    layer.open({
        title: (typeof title === "undefined" ? false : title),
        content: msg,
        time: (typeof time === "undefined" ? 0 : time),
        shade: 0.3,
        closeBtn: 0
    });
}


//成功消息
function SuccessBox(msg, title, time) {
    layer.msg(msg, {
        icon: 1,
        anim: 2,
        time: (typeof time === "undefined" ? 1500 : time),
        offset: ['70px', (document.body.offsetWidth - 205) + "px"]
    });
}

//失败消息
function ErrorBox(msg, title, time) {
    layer.open({
        icon: 2,
        title: (typeof title === "undefined" ? false : title),
        content: msg,
        time: (typeof time === "undefined" ? 0 : time),
        shade: 0.2,
        closeBtn: 0
    });
}

function LoadingBox(msg) {
    //layer.load(2, {
    //    title: msg,
    //    shade: [0.1, '#fff'] //0.1透明度的白色背景
    //});
    layer.msg(msg, {
        icon: 16
        , shade: 0.01
    });
}

//询问框
//@cfmMsg 主体内容
//@cb_yes 点确定的回调事件
//@title 标题名字(不填的话直接不显示标题栏)
//@cb_cancel 点取消的回调事件
function ConfirmBox(cfmMsg, cb_yes, title, cb_cancel) {
    layer.confirm(cfmMsg, {
        icon: 3,
        title: (typeof title === "string" ? title : false),
        shade: 0.1
    }, function (index) { //“确定”回调
        layer.close(index);
        if (typeof cb_yes === "function") cb_yes();
    }, function (index) { //“取消”回调
        layer.close(index);
        if (typeof cb_cancel === "function") cb_cancel();
    });
}

//自动展现、消失的简略信息
function AlertMsg(msg) {
    layer.msg(msg, {
        shift: 4
    });
}

//打开并显示页面帮助
function gHelp(msg) {
    layer.open({
        title: '帮助',
        icon: 3,
        content: msg,
        closeBtn: 0,
        shade: 0,
        shift: 3,
        move: false,
        btn: ['知道了']
    });
}

//自动展现、消失的简略信息
function AlertTip(id, msg, position) {
    var p;
    switch (position) {
        case "up": p = 1; break;
        case "down": p = 3; break;
        case "left": p = 4; break;
        case "right": p = 2; break;
        default: p = 1; break;
    }


    layer.tips(msg, '#' + id, {
        tips: [p, '#42a9dc']
    });
}

//打开一个内容为iframe页的弹窗
//@url: iframe的url
//@width: 弹窗的长度（像素）
//@height: 弹窗的高度（像素）
//@allowScrollbar: 允许滚动条 bool
//@showMaxMin: 是否显示最大最小化
//@maxOnOpen: 弹出即全屏
//@useShade: 是否使用遮罩(默认使用, 使用的话弹窗之外的点击无效)
//return: 弹窗的index
function gOpenModalWindow(title, url, width, height, allowScrollbar, showMaxMin, maxOnOpen, useShade) {
    if (typeof width === 'number')
        width = width + 'px';
    if (typeof height === 'number')
        height = height + 'px';
    if (typeof showMaxMin === "undefined") {
        showMaxMin = false;
    }
    if (typeof useShade === "undefined") {
        useShade = false;
    }
    if (typeof allowScrollbar === "undefined" || allowScrollbar === true || allowScrollbar === "true")
        allowScrollbar = 'yes';
    else
        allowScrollbar = 'no';

    var _index = layer.open({
        type: 2,
        title: title,
        shade: (useShade === true || useShade === "true") ? 0.1 : 0,
        //offset: '50px',
        maxmin: showMaxMin,
        area: [width, height],
        content: [url, allowScrollbar], //如果不想让iframe出现滚动条，这样写content: ['http://xxx.com', 'no']
    });

    if (maxOnOpen === true || maxOnOpen === "true") {
        layer.full(_index);
    }

    return _index;
}